﻿using AutoMapper;
using MediatR;
using MyMES.Domain.zmc;
using MyMES.Error;
using MyMES.Infrastructure.Interface;
using MyMES.Writer.API.Application.Commends.Proces;

namespace MyMES.Writer.API.Application.CommendHandlers.Proces
{
    public class UpdataProcessCommendHandlers : IRequestHandler<UpdataProcessCommends, APIResult<Process>>
    {
        private readonly IBaseRepository<Process> processRepository;
        private readonly IMapper mapper;

        public UpdataProcessCommendHandlers(IBaseRepository<Process> processRepository, IMapper mapper)
        {
            this.processRepository = processRepository;
            this.mapper = mapper;
        }

        /// <summary>
        /// 更新流程
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<APIResult<Process>> Handle(UpdataProcessCommends request, CancellationToken cancellationToken)
        {
            APIResult<Process> result = new APIResult<Process>();
            result.Code = APIEnum.修改成功;
            result.Msg = "修改成功";
            var process = mapper.Map<Process>(request);
            string sql = " update Process set  ProcessNo=@ProcessNo, ProcessName=@ProcessName,Processdescris=@Processdescris,Processroute=@Processroute,isvailable=@isvailable,IsDel=@IsDel,WorkOrderId=@WorkOrderId,Requisitionid=@Requisitionid,ProcessInfoId=@ProcessInfoId,NoticeId=@NoticeId where ProcessID=@ProcessID;";
             await processRepository.Update(process, sql);
            return result;
        }
    }
}
